﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using 充电桩上位机.Model.PTAConfig;

namespace 充电桩上位机.ViewModel.NetWorkRegister;

public class NetWorkRegisterViewModel : ObservableObject
{
    private bool _netIsBeUseConnect = false;
    public bool NetIsBeUseConnect
    {
        get => _netIsBeUseConnect;
        set => SetProperty(ref _netIsBeUseConnect, value);
    }

    [Category("离线模式使能颜色")]
    private Brush _offlineState = Brushes.Black;
    public Brush OfflineState
    {
        get => _offlineState;
        set => SetProperty(ref _offlineState, value);
    }

    [Category("离线模式使能")]
    private bool _offlineChecked = false;
    public bool OfflineChecked
    {
        get => _offlineChecked;
        set
        {
            if (value)
            {
                OfflineCheckedBack = Visibility.Hidden;
                OfflineState = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2563EB"));
            }
            else
            {
                OfflineCheckedBack = Visibility.Visible; 
                OfflineState = Brushes.Black;
            }
            SetProperty(ref _offlineChecked, value);
        }
    }

    private Visibility _offlineCheckedBack = Visibility.Hidden;
    public Visibility OfflineCheckedBack
    {
        get => _offlineCheckedBack;
        set => SetProperty(ref _offlineCheckedBack, value);
    }

    private Visibility _lTEIsWorking = Visibility.Hidden;
    public Visibility LTEIsWorking
    {
        get => _lTEIsWorking;
        set => SetProperty(ref _lTEIsWorking, value);
    }

    [Category("自动切换网络颜色")]
    private Brush _automaticState = Brushes.Black;
    public Brush AutomaticState
    {
        get => _automaticState;
        set => SetProperty(ref _automaticState, value);
    }


    [Category("自动切换网络")]
    private bool _automaticChecked = false;
    public bool AutomaticChecked
    {
        get => _automaticChecked;
        set
        {
            if (value)
                AutomaticState = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2563EB"));
            else
                AutomaticState = Brushes.Black;
            SetProperty(ref _automaticChecked, value);
        }
    }

    [Category("以太网启动颜色")]
    private Brush _etherNetState = Brushes.Black;
    public Brush EtherNetState
    {
        get => _etherNetState;
        set => SetProperty(ref _etherNetState, value);
    }
    [Category("以太网启动")]
    private bool _etherNetChecked = false;
    public bool EtherNetChecked
    {
        get => _etherNetChecked;
        set
        {
            if (value)
            {
                if (!AutomaticChecked)
                {
                    FourGChecked = false;
                    WIFIChecked = false;
                }
                EtherNetState = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2563EB"));
            }
            else
            {
                EtherNetState = Brushes.Black;
            }
            LTEIsWorking = (WIFIChecked == true || value == true) ? Visibility.Visible : Visibility.Hidden;
            NetIsBeUseConnect = value | WIFIChecked | FourGChecked;
            SetProperty(ref _etherNetChecked, value);
        }
    }

    [Category("WIFI启动颜色")]
    private Brush _wIFIState = Brushes.Black;
    public Brush WIFIState
    {
        get => _wIFIState;
        set => SetProperty(ref _wIFIState, value);
    }
    [Category("WIFI启动")]
    private bool _wIFIChecked = false;
    public bool WIFIChecked
    {
        get => _wIFIChecked;
        set
        {
            if (value)
            {
                if (!AutomaticChecked)
                {
                    FourGChecked = false;
                    EtherNetChecked = false;
                }
                WIFIState = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2563EB"));
            }
            else
            {
                WIFIState = Brushes.Black;
            }
            LTEIsWorking = (value == true || EtherNetChecked == true) ? Visibility.Visible : Visibility.Hidden;
            NetIsBeUseConnect = EtherNetChecked | value | FourGChecked;
            SetProperty(ref _wIFIChecked, value);
        }
    }
    [Category("WIFI SSID")]
    private string _wifiSSID = string.Empty;
    public string WifiSSID
    {
        get => _wifiSSID;
        set => SetProperty(ref _wifiSSID, value);
    }
    [Category("WIFI 密码")]
    private string _wifiPassword = string.Empty;
    public string WifiPassword
    {
        get => _wifiPassword;
        set => SetProperty(ref _wifiPassword, value);
    }

    [Category("LTE启动（4G）颜色")]
    private Brush _fourGState = Brushes.Black;
    public Brush FourGState
    {
        get => _fourGState;
        set => SetProperty(ref _fourGState, value);
    }
    [Category("LTE启动（4G）")]
    private bool _fourGChecked = false;
    public bool FourGChecked
    {
        get => _fourGChecked;
        set
        {
            if (value)
            {
                if (!AutomaticChecked)
                {
                    WIFIChecked = false;
                    EtherNetChecked = false;
                }
                FourGState = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2563EB"));
            }
            else
            {
                FourGState = Brushes.Black;
            }
            LTEIsWorking = (WIFIChecked == true || EtherNetChecked == true) ? Visibility.Visible : Visibility.Hidden;
            NetIsBeUseConnect = value | WIFIChecked | EtherNetChecked;
            //FourGEditEnable = value;
            SetProperty(ref _fourGChecked, value);
        }
    }
    [Category("APN 地址")]
    private string _aPNAddress = string.Empty;
    public string APNAddress
    {
        get => _aPNAddress;
        set => SetProperty(ref _aPNAddress, value);
    }
    [Category("APN用户名称")]
    private string _aPNUserName = string.Empty;
    public string APNUserName
    {
        get => _aPNUserName;
        set => SetProperty(ref _aPNUserName, value);
    }
    [Category("APN用户密码")]
    private string _aPNPassword = string.Empty;
    public string APNPassword
    {
        get => _aPNPassword;
        set => SetProperty(ref _aPNPassword, value);
    }

    [Category("EtherNet IP固定地址输入内容显示或隐藏")]
    private Visibility _enableEtherNetShow = Visibility.Hidden;
    public Visibility EnableEtherNetShow
    {
        get => _enableEtherNetShow;
        set => SetProperty(ref _enableEtherNetShow, value);
    }
    [Category("EtherNet IP固定地址切换状态符")]
    private bool _enableEtherNetIPState = false;
    public bool EnableEtherNetIPState
    {
        get => _enableEtherNetIPState;
        set
        {
            if (value)
                EnableEtherNetShow = Visibility.Visible;
            else
                EnableEtherNetShow = Visibility.Hidden;
            SetProperty(ref _enableEtherNetIPState, value);
        }
    }
    [Category("IP Address")]
    private string _iPAddress = string.Empty;
    public string IPAddress
    {
        get => _iPAddress;
        set => SetProperty(ref _iPAddress, value);
    }
    [Category("IP Mask")]
    private string _iPMask = string.Empty;
    public string IPMask
    {
        get => _iPMask;
        set => SetProperty(ref _iPMask, value);
    }
    [Category("Default GetWay")]
    private string _defaultGetWay = string.Empty;
    public string DefaultGetWay
    {
        get => _defaultGetWay;
        set => SetProperty(ref _defaultGetWay, value);
    }
    [Category("IP固定地址输入内容显示或隐藏")]
    private Visibility _enableIPShow = Visibility.Hidden;
    public Visibility EnableIPShow
    {
        get => _enableIPShow;
        set => SetProperty(ref _enableIPShow, value);
    }
    [Category("IP固定地址切换状态符")]
    private bool _iPToggleState = false;
    public bool IPToggleState
    {
        get => _iPToggleState;
        set {
            if (value)
                EnableIPShow = Visibility.Visible;
            else
                EnableIPShow = Visibility.Hidden;
            SetProperty(ref _iPToggleState, value); 
        }
    }
    [Category("DNS切换状态符")]
    private bool _autoDNSInit = false;
    public bool AutoDNSInit
    {
        get => _autoDNSInit;
        set
        {
            if (value)
                DNSState = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2563EB"));
            else
                DNSState = Brushes.Black;
            SetProperty(ref _autoDNSInit, value);
        }
    }
    [Category("DNS启动颜色")]
    private Brush _dNSState = Brushes.Black;
    public Brush DNSState
    {
        get => _dNSState;
        set => SetProperty(ref _dNSState, value);
    }
    [Category("首选DNS")]
    private string _dNSFirst = string.Empty;
    public string DNSFirst
    {
        get => _dNSFirst;
        set => SetProperty(ref _dNSFirst, value);
    }
    [Category("备选DNS")]
    private string _dNSSecond = string.Empty;
    public string DNSSecond
    {
        get => _dNSSecond;
        set => SetProperty(ref _dNSSecond, value);
    }
    #region 全球化字符
    private string _network_Registers = string.Empty;
    public string Network_Registers
    {
        get => _network_Registers;
        set => SetProperty(ref _network_Registers, value);
    }
    private string _offline_modeText = string.Empty;
    public string Offline_modeText
    {
        get => _offline_modeText;
        set => SetProperty(ref _offline_modeText, value);
    }
    private string _automatic_network_switching = string.Empty;
    public string Automatic_network_switching
    {
        get => _automatic_network_switching;
        set => SetProperty(ref _automatic_network_switching, value);
    }
    private string _ethenetText = string.Empty;
    public string EthenetText
    {
        get => _ethenetText;
        set => SetProperty(ref _ethenetText, value);
    }
    private string _enable_static_IP = string.Empty;
    public string Enable_static_IP
    {
        get => _enable_static_IP;
        set => SetProperty(ref _enable_static_IP, value);
    }
    private string _iP_Address = string.Empty;
    public string IP_Address
    {
        get => _iP_Address;
        set => SetProperty(ref _iP_Address, value);
    }
    private string _maskText = string.Empty;
    public string MaskText
    {
        get => _maskText;
        set => SetProperty(ref _maskText, value);
    }
    private string _default_gateway = string.Empty;
    public string Default_gateway
    {
        get => _default_gateway;
        set => SetProperty(ref _default_gateway, value);
    }
    private string _autoDNSInitText = string.Empty;
    public string AutoDNSInitText
    {
        get => _autoDNSInitText;
        set => SetProperty(ref _autoDNSInitText, value);
    }
    private string _autoFirstDNSText = string.Empty;
    public string AutoFirstDNSText
    {
        get => _autoFirstDNSText;
        set => SetProperty(ref _autoFirstDNSText, value);
    }
    private string _autoSecondDNSText = string.Empty;
    public string AutoSecondDNSText
    {
        get => _autoSecondDNSText;
        set => SetProperty(ref _autoSecondDNSText, value);
    }
    private string _wI_FI_Init_Text = string.Empty;
    public string WI_FI_Init_Text
    {
        get => _wI_FI_Init_Text;
        set => SetProperty(ref _wI_FI_Init_Text, value);
    }
    private string _wI_FI_Text = string.Empty;
    public string WI_FI_Text
    {
        get => _wI_FI_Text;
        set => SetProperty(ref _wI_FI_Text, value);
    }
    private string _wIFI_PassWord_Text = string.Empty;
    public string WIFI_PassWord_Text
    {
        get => _wIFI_PassWord_Text;
        set => SetProperty(ref _wIFI_PassWord_Text, value);
    }
    private string _lTE_Init_Text = string.Empty;
    public string LTE_Init_Text
    {
        get => _lTE_Init_Text;
        set => SetProperty(ref _lTE_Init_Text, value);
    }
    private string _aPN_Text = string.Empty;
    public string APN_Text
    {
        get => _aPN_Text;
        set => SetProperty(ref _aPN_Text, value);
    }
    private string _lTE_User_Name = string.Empty;
    public string LTE_User_Name
    {
        get => _lTE_User_Name;
        set => SetProperty(ref _lTE_User_Name, value);
    }
    private string _lTE_Password_Text = string.Empty;
    public string LTE_Password_Text
    {
        get => _lTE_Password_Text;
        set => SetProperty(ref _lTE_Password_Text, value);
    }
    #endregion
    public NetWorkRegisterViewModel()
    {
        #region 全球化
        Network_Registers = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "Network Regisiter");
        Offline_modeText = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "Off-grid mode");
        Automatic_network_switching = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "Automatic network switching");
        EthenetText = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "Ethenet");
        Enable_static_IP = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "Enable static IP");
        IP_Address = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "IP Address");
        MaskText = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "Mask");
        Default_gateway = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "Default gateway");
        AutoDNSInitText = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "Auto DNS Init");
        AutoFirstDNSText = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "Auto First DNS");
        AutoSecondDNSText = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "Auto Second DNS");
        WI_FI_Init_Text = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "WI-FI(Supports 2.4Hz Only)");
        WI_FI_Text = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "WI-FI");
        WIFI_PassWord_Text = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "WI-FI Password");
        LTE_Init_Text = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "LTE Init");
        APN_Text = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "APN");
        LTE_User_Name = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "LTE User Name");
        LTE_Password_Text = MainWindowViewModel.SetLanguage(MainWindowViewModel.globellanguage, "LTE Password");
        #endregion
        OfflineChecked = MainWindowViewModel.pTAConfigModel!.离线模式使能 ?? false;
        AutomaticChecked = MainWindowViewModel.pTAConfigModel!.自动切换网络 ?? false;
        EtherNetChecked = MainWindowViewModel.pTAConfigModel!.以太网启用 ?? false;
        WIFIChecked = MainWindowViewModel.pTAConfigModel!.WIFI启用 ?? false;
        FourGChecked = MainWindowViewModel.pTAConfigModel!.LTE启用 ?? false;
        WifiSSID = MainWindowViewModel.pTAConfigModel!.WIFI_SSID!;
        WifiPassword = MainWindowViewModel.pTAConfigModel!.WIFI密码!;
        APNAddress = MainWindowViewModel.pTAConfigModel!.APN!;
        APNUserName = MainWindowViewModel.pTAConfigModel!.APN_User!;
        APNPassword = MainWindowViewModel.pTAConfigModel!.APN_Password!;
        EnableEtherNetIPState = MainWindowViewModel.pTAConfigModel!.静态IP使能 ?? false;
        IPAddress = MainWindowViewModel.pTAConfigModel!.静态IP!;
        IPMask = MainWindowViewModel.pTAConfigModel!.默认网关!;
        DefaultGetWay = MainWindowViewModel.pTAConfigModel!.子网掩码!;
        AutoDNSInit = MainWindowViewModel.pTAConfigModel!.自定义DNS ?? false;
        DNSFirst = MainWindowViewModel.pTAConfigModel!.自定义首选DNS!;
        DNSSecond = MainWindowViewModel.pTAConfigModel!.自定义备用DNS!;

    }
}
